#include <stdio.h>

int main(int argc, char const *argv[])
{
    if( argc != 3)
    {
        printf("Pls input: ./a.out <dst file name> <src file name>\n");
        return -1;
    }    

    FILE *fpDst = fopen(argv[1], "w");
    FILE *fpSrc = fopen(argv[2], "r");
    if( NULL == fpDst || NULL == fpSrc)
    {
        printf("Fail to open file\n");
        return -1;
    }

    char cBuff[1024] = {0};
    char *pRet = NULL;
    int iCounter = 0;

    while ( NULL != ( pRet = fgets(cBuff, sizeof(cBuff), fpSrc) ) )
    {
        fputs(cBuff, fpDst);
        ++iCounter;
    }

    if( ferror(fpSrc) )
    {
        perror("Fail to fgets");
        return -1;
    }

    fclose(fpDst);
    fclose(fpSrc);
    
    printf("Success to copy total %d lines from src file %s to dst file %s\n",
            iCounter, argv[2], argv[1]);


    return 0;
}


/*
使用函数 fgets 和 fputs 复制一个文本文件
*/